﻿using System;
using System.Web;
using System.Web.Mvc;
using Manazra.Models.Repository;
using Manazra.Models;

namespace Manazra.Controllers.Filters
{
    public class BasePreControllerActionFilter : ActionFilterAttribute
    {
        private ArticleRepository articleRep = new ArticleRepository();

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //authenticate user request
            UserAuth UserAuth = new UserAuth();
            UserAuth.Authenticate();

            //pass authentication information to view
            filterContext.Controller.ViewData["UserAuth"] = UserAuth;

            //pass categories list data to master page
            if (!filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Controller.ViewData["ArticleCategories"] = articleRep.GetCategories();
            }
            base.OnActionExecuting(filterContext);
        }
    }
}
